
import 'package:flutter/cupertino.dart';

class TimeUtil{

  // 将Duration转化为本地时间格式 输出01：00
  static String toLocalTime(double time) {
    Duration duration = Duration(milliseconds: time.toInt());
    int minutes = duration.inMinutes;
    int seconds = duration.inSeconds % 60;

    // 使用 padLeft(2, '0') 确保分钟和秒钟都是两位数
    String minutesStr = minutes.toString().padLeft(2, '0');
    String secondsStr = seconds.toString().padLeft(2, '0');

    return '$minutesStr:$secondsStr';
  }

  // 将播放时间转化为duration
  static Duration toDuration(String time){
    final t = time.replaceAll("[", "").split(".");
    final m = int.parse(t[0]);
    final s = int.parse(t[1]);
    debugPrint("$m===$s");
    return Duration(seconds: m * 60 +s);
  }

}